package com.dkd.easybook.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.easybook.domain.EbNotes;
import com.dkd.easybook.service.IEbNotesService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 笔记列表Controller
 *
 * @author itheima
 * @date 2024-12-13
 */
@Api(tags = "笔记列表Controller")
@RestController
@RequestMapping("/easybook/notesList")
public class EbNotesController extends BaseController
{
    @Autowired
    private IEbNotesService ebNotesService;

    /**
     * 查询笔记列表列表
     */
    @ApiOperation("查询笔记列表列表")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:list')")
    @GetMapping("/list")
    public TableDataInfo list(EbNotes ebNotes)
    {
        startPage();
        List<EbNotes> list = ebNotesService.selectEbNotesList(ebNotes);
        return getDataTable(list);
    }

    /**
     * 导出笔记列表列表
     */
    @ApiOperation("导出笔记列表列表")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:export')")
    @Log(title = "笔记列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EbNotes ebNotes)
    {
        List<EbNotes> list = ebNotesService.selectEbNotesList(ebNotes);
        ExcelUtil<EbNotes> util = new ExcelUtil<EbNotes>(EbNotes.class);
        util.exportExcel(response, list, "笔记列表数据");
    }

    /**
     * 获取笔记列表详细信息
     */
    @ApiOperation("获取笔记列表详细信息")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:query')")
    @GetMapping(value = "/{noteId}")
    public AjaxResult getInfo(@PathVariable("noteId") Long noteId)
    {
        return success(ebNotesService.selectEbNotesByNoteId(noteId));
    }

    /**
     * 新增笔记列表
     */
    @ApiOperation("新增笔记列表")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:add')")
    @Log(title = "笔记列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EbNotes ebNotes)
    {
        return toAjax(ebNotesService.insertEbNotes(ebNotes));
    }

    /**
     * 修改笔记列表
     */
    @ApiOperation("修改笔记列表")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:edit')")
    @Log(title = "笔记列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EbNotes ebNotes)
    {
        return toAjax(ebNotesService.updateEbNotes(ebNotes));
    }

    /**
     * 删除笔记列表
     */
    @ApiOperation("删除改笔记列表")
    @PreAuthorize("@ss.hasPermi('easybook:notesList:remove')")
    @Log(title = "笔记列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noteIds}")
    public AjaxResult remove(@PathVariable Long[] noteIds)
    {
        return toAjax(ebNotesService.deleteEbNotesByNoteIds(noteIds));
    }
}
